package com.sitech.portal.server.action;

import com.sitech.ibnms.core.JGridBaseAction;
import com.sitech.ibnms.util.AppException;
import com.sitech.ibnms.util.RandomGUID;
import com.sitech.portal.server.form.MessageSettingForm;
import com.sitech.portal.server.service.IMessageSettingService;

public class MessageSettingAction extends JGridBaseAction {

	IMessageSettingService msgSettingService;
	MessageSettingForm theForm;
	String flag;
	
	public String updateMessageSetting() throws AppException{
		try{
			String loginId = this.getCurrentUser().getLOGIN_ID();
			MessageSettingForm queryRst = msgSettingService.queryMessageSettingByLoginId(loginId);
			if(queryRst!=null&&queryRst.getGuid()!=null&&!queryRst.getGuid().isEmpty()){
				// 更新
				theForm.setLogin_id(loginId);
				msgSettingService.updateMessageSetting(theForm);
			}else{
				// 插入
				theForm.setGuid(RandomGUID.getRandomGUID());
				theForm.setLogin_id(loginId);
				msgSettingService.saveMessageSetting(theForm);
			}
			flag = "true";
		}catch(Exception ex){
			flag = "false";
			ex.printStackTrace();
			throw new AppException("保存消息设置时发生异常!",ex);
		}
		return SUCCESS;
	}
	
	public IMessageSettingService getMsgSettingService() {
		return msgSettingService;
	}

	public void setMsgSettingService(IMessageSettingService msgSettingService) {
		this.msgSettingService = msgSettingService;
	}

	public MessageSettingForm getTheForm() {
		return theForm;
	}

	public void setTheForm(MessageSettingForm theForm) {
		this.theForm = theForm;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}
	
}
